//
//  HomeOwnViewModel.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/2/3.
//

import Foundation
import LeanCloud
//API站点
class ApiSitesViewModel : BaseViewModel {
    
    @Published var items = [ApiSitesBean]()
    @Published var status = ""
    
    func getData(_ isRefresh: Bool = false) {
        requestList(isRefresh: isRefresh) {
            let query = LCQuery(className: "ApiSites")
            query.whereKey("sort", .descending) //降序
            query.limit = self.pageSize
            query.skip = self.pageNo * self.pageSize
            let list =  try await LeancloudManager.instance.getList(query: query, modeType: ApiSitesBean.self)
            try check(!isRefresh || !list.isEmpty, "暂无站点信息")
            return list
        } suc: { list in
            self.status = ""
            if isRefresh {
                self.items = list
            } else {
                self.items.append(contentsOf: list)
            }
        } fail: {
            self.status = $0.message
        }
    }
    
}
